//
//  XHQBaseCell.m
//  XiongMaoJiaSu
//
//  Created by 徐汉卿 on 16/5/25.
//  Copyright © 2016年 ISOYasser. All rights reserved.
//

#import "XHQBaseCell.h"


@implementation XHQBaseCell


+(instancetype)cellWithTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath idf:(NSString *)ID{
    XHQBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        
        //        cell.tableView = tableView;
        //
        
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //新方法 ,不知道有没有问题
    //赋值indexPath
    cell.IndexPath = indexPath;
    
    //可变属性
    NSInteger   row =  [tableView.dataSource tableView:tableView numberOfRowsInSection:indexPath.section];
    
    
    
    if (cell.hiddenSpearLine == YES) {
        cell.bottomLine.hidden = YES;
        
        
        
    }else{
        if (row ==(indexPath.row +1)) {
            cell.bottomLine.hidden = YES;
        }else{
            cell.bottomLine.hidden = NO;
            
        }
        
        
        
        if (indexPath.row ==0) {
            cell.topLine.hidden = YES;
            
        }else{
            cell.topLine.hidden = YES;
            
        }
        
    }
    
    return cell;

}



+(instancetype)cellWithTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID =@"shop";
    XHQBaseCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
       
        //        cell.tableView = tableView;
        //
        
    }
    
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //新方法 ,不知道有没有问题
    //赋值indexPath
    cell.IndexPath = indexPath;
    
    //可变属性
    NSInteger   row =  [tableView.dataSource tableView:tableView numberOfRowsInSection:indexPath.section];

    
  
    if (cell.hiddenSpearLine == YES) {
        cell.bottomLine.hidden = YES;
    
        cell.bottomLine.hidden = YES;
        
    }else{
        if (row ==(indexPath.row +1)) {
            cell.bottomLine.hidden = YES;
        }else{
            cell.bottomLine.hidden = NO;
            
        }
        
        
        
        if (indexPath.row ==0) {
            cell.topLine.hidden = YES;
            
        }else{
            cell.topLine.hidden = YES;
            
        }

    }
    
      return cell;
    
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.hiddenSpearLine = NO;
        //这个方法就得放在line前边   设置hidden后边
        [self buitUI];
        
        self.bottomLine = [UIView new];
        self.bottomLine.backgroundColor =  kMainColorBoradLine;
        [self.contentView addSubview:self.bottomLine];
        
        [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.contentView);
            make.left.equalTo(self.contentView).offset(12);
             make.right.equalTo(self.contentView).offset(-12);
            make.height.mas_equalTo(0.5);
        }];
        
        
        self.topLine = [UIView new];
        self.topLine.backgroundColor =   kMainColorBoradLine;  // kMainColorBoradLine;
        [self.contentView addSubview:self.topLine];
        
        [self.topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(0.5);
        }];
        
        //        self.topLine.backgroundColor = [UIColor greenColor];
        //        self.bottomLine.backgroundColor = [UIColor redColor];
        
        
        
    }
    return  self;
}



/**
 *  子类去实现
 */
-(void)buitUI
{
    
}


-(void)layoutSubviews{
    [super layoutSubviews];
    
    
}


-(void)setHiddenSpearLine:(BOOL)hiddenSpearLine
{
    _hiddenSpearLine = hiddenSpearLine;
    
    
    if (self.hiddenSpearLine == YES) {
        self.bottomLine.hidden = YES;
 
    }

}





@end
